﻿using System;
using System.Net.Mail;
using System.Text;
using NENAData.Errors;
using NENAData.LINQ;
using NENAData.NENAProvinces;

namespace NENAData.Email
{
    public class Message
    {
        public static void ApplicationCompleted(int intMemberId)
        {
            MailMessage oMessage = new MailMessage();

            NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
            Member oMember = oNENAMember.GetMember(intMemberId);

            AffiliateDirectors oProvinceAffiliate = new AffiliateDirectors();
            Directors_Provincal oDirectorsProvincal = oProvinceAffiliate.GetDirectors_byAffiliateID(oMember.Affiliate_ID);

            MembersCommittee oCommittee = new MembersCommittee();
            var oCommitteeMember = oCommittee.MemberCommitteeDetails(Convert.ToInt32(oDirectorsProvincal.Members_Contact_ID));

            NENAAffiliate oNENAAffiliate = new NENAAffiliate();
            Affiliate oAffiliiate = oNENAAffiliate.GetAffiliate_byAffiliateID(oMember.Affiliate_ID);

            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append("Thank you for visiting the NENA website  <b> ")
                .Append(oMember.FirstName).Append(" ").Append(oMember.LastName).Append("</b>.").Append("<br />").Append("<br />");
            strbuilder.Append("You have applied for membership to: <b>").Append(
                oAffiliiate.Affiliate_Description).Append("</b>").Append("<br />");
            strbuilder.Append("The ").Append(oAffiliiate.Affiliate_Description).Append(" fee is <b>").Append(
                string.Format("{0,-10:C}", oAffiliiate.Membership_Fee)).Append("</b>").Append("<br />").Append("<br />");
            strbuilder.Append("Please send a cheque to: <b> ").Append(oCommitteeMember.FullName)
                .Append("</b>").Append("<br />");
            strbuilder.Append("Address: <b>").Append(oCommitteeMember.Address_1).
                Append(oCommitteeMember.Address_2).Append("</b>").Append("<br />");
            strbuilder.Append("City: <b>").Append(oCommitteeMember.City).Append("</b>").Append("<br />");
            strbuilder.Append("Province: <b>").Append(oCommitteeMember.Province).Append("</b>").Append("<br />");
            strbuilder.Append("Postal Code: <b>").Append(oCommitteeMember.Postal_Code)
                .Append("</b>").Append("<br />");
            strbuilder.Append("Country: <b>Canada</b>").Append("<br />").Append("<br />");
            strbuilder.Append("Once the payment process has been completed you will recieve an email invoice.").
                Append("<br />");
            strbuilder.Append("If you have any questions, you can contact your affiliate membership provider.").Append("<br />");
            strbuilder.Append(" Contact: <b>").Append(oCommitteeMember.FullName)
                .Append("</b>").Append("<br />");
            strbuilder.Append(" Email: <b>").Append(oDirectorsProvincal.ContactEmail)
                .Append("</b>").Append("<br />").Append("<br />");
            strbuilder.Append("Thank you for you application.").Append("<br />").Append("<br />");
            strbuilder.Append("Sincerely, ").Append("<br />").Append(oAffiliiate.Affiliate_Full).Append(" Membership") ;

            oMessage.From = new MailAddress(oDirectorsProvincal.ContactEmail, oDirectorsProvincal.Description + " Membership Approver");
            oMessage.To.Add(new MailAddress(oMember.EmailAddress));
            oMessage.Bcc.Add(new MailAddress("websiteadministrator@nena.ca"));

            oMessage.IsBodyHtml = true;
            oMessage.Subject = "NENA Membership Application";
            oMessage.Body = strbuilder.ToString();

            //SmtpClient client = new SmtpClient("rarsk.com", 25);
            //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");
            SmtpClient client = new SmtpClient();
            client.Send(oMessage);
        }
        
         public static void PaymentCompleted(int intMemberId, string strTransactionId, int intAffiliateId)
        {
            MailMessage oMessage = new MailMessage();

            AffiliateDirectors oProvinceAffiliate = new AffiliateDirectors();
            //Directors_Provincal oDirectors_Provincal = new Directors_Provincal();
            Directors_Provincal oDirectors_Provincal = oProvinceAffiliate.GetDirectors_byAffiliateID(intAffiliateId);

            //Member oMember = new Member();
            NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
            Member oMember = oNENAMember.GetMember(intMemberId);

            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append("This email is to confirm we recieved your NENA payment. <br />");
            strbuilder.Append("You can view your receipt online at this link <br /> ");
            strbuilder.Append("http://membership.nena.ca/paypal/ViewTransactionReciept.aspx?Member_ID=").Append(intMemberId.ToString()).Append("&TransactionID=").Append(strTransactionId);
            strbuilder.Append("<br /><br />You can find this receipt as part of your NENA profile located at:").Append("http://membership.nena.ca/"); 
            strbuilder.Append("<br />Thank you for completing this transaction. <br /> <br />");
            strbuilder.Append("Sincerely,<br />");
             strbuilder.Append(oDirectors_Provincal.Description).Append(" Membership Approver");

            oMessage.From = new MailAddress(oDirectors_Provincal.ContactEmail, oDirectors_Provincal.Description + " Membership Approver");
            oMessage.To.Add(new MailAddress(oMember.EmailAddress));
            
        //omessage.To.Add(New MailAddress("gary.pronych@gmail.com"))

            oMessage.IsBodyHtml = true;
            oMessage.Subject = "NENA Membership Payment Received";

            oMessage.Body = strbuilder.ToString();

            SmtpClient client = new SmtpClient();
            //SmtpClient client = new SmtpClient("rarsk.com", 25);
            //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");

            client.Send(oMessage);

        }

         public static void IpnAdministrationEmail(string strMessage)
         {
             StringBuilder strbuilder = new StringBuilder();
             strbuilder.Append(strMessage).Append(" <br />").AppendLine();

             MailMessage omessage = new MailMessage();
             omessage.From = new MailAddress("webmaster@Nena.ca");
             omessage.To.Add(new MailAddress("gary.pronych@gmail.com"));

             omessage.IsBodyHtml = true;
             omessage.Subject = "IPN Notification";

             omessage.Body = strbuilder.ToString();

             SmtpClient client = new SmtpClient();
             //SmtpClient client = new SmtpClient("rarsk.com", 25);
             //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");
             client.Send(omessage);

         }

         public static void EventPaymentCompleted(int intMemberId, int intTransactionPaymentId, int intEventId)
         {
             MailMessage oMessage = new MailMessage();

             //Member oMember = new Member();
             NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
             Member oMember = oNENAMember.GetMember(intMemberId);

             StringBuilder strbuilder = new StringBuilder();
             strbuilder.Append("Thank you for completing your event registration <b> ")
                    .Append(oMember.FirstName).Append(" ").Append(oMember.LastName).Append("</b>.").Append("<br />").Append("<br />");
             strbuilder.Append("This email is to confirm we recieved your NENA conference payment. <br />");
             strbuilder.Append("You can view your receipt online at this link <br /> ");
             strbuilder.Append("http://membership.nena.ca/paypal/ViewTransactionReciept.aspx?Member_ID=").Append(intMemberId.ToString()).Append("&TransactionID=").Append(intTransactionPaymentId);
             strbuilder.Append("<br /><br />You can print a copy of your event registration itinerary at this link <br />");
             strbuilder.Append("http://events.nena.ca/Confirmation/Conference/NENAConference2012.aspx?MemberId=").Append(intMemberId).Append("&EventId=").Append(intEventId);
             strbuilder.Append("<br />Thank you for completing your online registration. <br /> <br />");
             strbuilder.Append("Sincerely,<br />");
             strbuilder.Append("NENA 2012 Conference Committee");

             oMessage.From = new MailAddress("conference@nena.ca", "NENA 2012 Conference");
             oMessage.To.Add(new MailAddress(oMember.EmailAddress));
             oMessage.Bcc.Add(new MailAddress("conference@nena.ca"));
             oMessage.Bcc.Add(new MailAddress("gary.pronych@gmail.com"));
             //omessage.To.Add(New MailAddress("gary.pronych@gmail.com"))

             oMessage.IsBodyHtml = true;
             oMessage.Subject = "NENA Event Payment Received";

             oMessage.Body = strbuilder.ToString();

             SmtpClient client = new SmtpClient();
             //SmtpClient client = new SmtpClient("rarsk.com", 25);
             //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");

             client.Send(oMessage);

         }

         public static void DuplicateAccount(int intMemberID, int intAffiliateID)
         {
             AffiliateDirectors oProvinceAffiliate = new AffiliateDirectors();
             Directors_Provincal oDirectors_Provincal = oProvinceAffiliate.GetDirectors_byAffiliateID(intAffiliateID);

             Member oMember = new Member();
             NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
             oMember = oNENAMember.GetMember(intMemberID);

             StringBuilder strbuilder = new StringBuilder();
             strbuilder.Append("Duplicate member has been paid, but we detected it is a duplicate account <br />").AppendLine();
             strbuilder.Append("The Web Administrator will review this account <br/>");
             strbuilder.Append(" <br />Account ID:").Append(intMemberID).AppendLine();
             strbuilder.Append(" <br />Name: ").Append(oMember.FirstName).Append(" ").Append(oMember.LastName).AppendLine();

             MailMessage omessage = new MailMessage();
             omessage.From = new MailAddress(oDirectors_Provincal.ContactEmail, oDirectors_Provincal.Description + " Membership Approver");
             omessage.To.Add(new MailAddress(oDirectors_Provincal.ContactEmail));
             //omessage.CC.Add(new MailAddress("webmaster@nena.ca"));
             omessage.CC.Add(new MailAddress("gary.pronych@gmail.com"));

             omessage.IsBodyHtml = true;
             omessage.Subject = "Duplicate Member Detected";

             omessage.Body = strbuilder.ToString();

             SmtpClient client = new SmtpClient();
             //SmtpClient client = new SmtpClient("rarsk.com", 25);
             //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");
             client.Send(omessage);

             ErrHandler.WriteError("Duplicate Account detected: " + intMemberID.ToString());
         }

         public static void DuplicateAccount(int intMemberID)
         {
             Member oMember = new Member();
             NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
             oMember = oNENAMember.GetMember(intMemberID);

             StringBuilder strbuilder = new StringBuilder();
             strbuilder.Append("Duplicate member has been paid, but we detected it is a duplicate account <br />").AppendLine();
             strbuilder.Append("The Web Administrator will review this account <br/>");
             strbuilder.Append(" <br />Account ID:").Append(intMemberID).AppendLine();
             strbuilder.Append(" <br />Name: ").Append(oMember.FirstName).Append(" ").Append(oMember.LastName).AppendLine();

             MailMessage omessage = new MailMessage();
             omessage.From = new MailAddress("NENA_Duplicate_Member@Nena.ca");
             //omessage.CC.Add(new MailAddress("webmaster@nena.ca"));
             omessage.To.Add(new MailAddress("gary.pronych@gmail.com"));
             omessage.CC.Add(new MailAddress("gary.pronych@gmail.com"));

             omessage.IsBodyHtml = true;
             omessage.Subject = "Duplicate Member Detected";

             omessage.Body = strbuilder.ToString();

             SmtpClient client = new SmtpClient();
             //SmtpClient client = new SmtpClient("rarsk.com", 25);
             //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");
             client.Send(omessage);

             ErrHandler.WriteError("Duplicate Account detected: " + intMemberID.ToString());
         }

         //public static void NewPassword(int intMemberID, int intAffiliateID)
         //{
         //    MailMessage omessage = new MailMessage();

         //    AffiliateDirectors oProvinceAffiliate = new AffiliateDirectors();
         //    Directors_Provincal oDirectors_Provincal = new Directors_Provincal();
         //    oDirectors_Provincal = oProvinceAffiliate.GetDirectors_byAffiliateID(intAffiliateID);

         //    Member oMember = new Member();
         //    NENAMember.NENAMember oNENAMember = new NENAMember.NENAMember();
         //    oMember = oNENAMember.GetMember(intMemberID);

         //    StringBuilder strbuilder = new StringBuilder();
         //    strbuilder.Append("Duplicate member has been paid, but we detected it is a duplicate account").AppendLine();
         //    strbuilder.Append("Please review the member accountID:").Append(intMemberID).AppendLine();
         //    strbuilder.Append("Name: ").Append(oMember.FirstName).Append(" ").Append(oMember.LastName).AppendLine();

         //    omessage.From = new MailAddress(oDirectors_Provincal.ContactEmail, oDirectors_Provincal.Description + " Membership Approver");
         //    omessage.To.Add(new MailAddress("gary.pronych@gmail.com"));

         //    omessage.IsBodyHtml = true;
         //    omessage.Subject = "Duplicate Member Detected";

         //    omessage.Body = strbuilder.ToString();

         //    SmtpClient client = new SmtpClient("localhost");
         //    client.Send(omessage);

         //    ErrHandler.WriteError("Duplicate Account detected: " + intMemberID.ToString());
         //}

        public static void PasswordReset(string strAccountName, string strEmail, string strPassword)
        {
                StringBuilder strbuilder = new StringBuilder();

                strbuilder.Append("<br/>Hello, you have requested a new NENA.ca password; below are your new login credentials: <br />").AppendLine().AppendLine();
                strbuilder.Append("&nbsp;&nbsp;Username: <b>").Append(strAccountName).Append("</b> <br />").AppendLine();
                strbuilder.Append("&nbsp;&nbsp;Password: <b>").Append(strPassword).Append("</b> <br />").AppendLine().AppendLine();
                strbuilder.Append("<br />If you are attempting to renew your account or update your demographics, please visit our Membership website at").AppendLine().Append("http://www.nena.ca/membership ").AppendLine().AppendLine();
                strbuilder.Append("<br />if you are a current member, you can enter your password and username in the login box on the website").AppendLine().Append("http://www.nena.ca ").AppendLine().AppendLine();
                strbuilder.Append("<br />If we can be of any assistance to you please feel free to contact us.").AppendLine();
                strbuilder.Append("<br />You can contact us through the NENA Message Board link on the NENA website if you are a current member.").AppendLine();
                strbuilder.Append("<br />If you are unable to log in to your NENA account, please reply to this email.").AppendLine().AppendLine();
                strbuilder.Append("<br /><br />Sincerely,").AppendLine().Append("<br />NENA Site Administrators");

            MailMessage omessage = new MailMessage();
            omessage.From = new MailAddress("WebSiteAdministrator@nena.ca", "NENA WebSite Administrator");
            omessage.To.Add(new MailAddress(strEmail));
            omessage.Subject = "NENA Password Reset";
            omessage.IsBodyHtml = true;
            omessage.Body = strbuilder.ToString();

            SmtpClient client = new SmtpClient();
            //SmtpClient client = new SmtpClient("rarsk.com", 25);
            //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");

            client.Send(omessage);
        }

                public static void CreatedNewAccount(Member pMember, string strPassword)
        {
                StringBuilder strbuilder = new StringBuilder();

                strbuilder.Append("Hello ").Append(pMember.FirstName).Append(" ")
                    .Append(pMember.LastName).AppendLine();
                strbuilder.Append("<br />This Email is to confirm we have created your NENA.ca web account. <br />").AppendLine();
                strbuilder.Append("below are your new login credentials for our web site: <br />").AppendLine().AppendLine();
                strbuilder.Append("<br />&nbsp;&nbsp;Username: <b>").Append(pMember.CS_UserName).Append("</b>").AppendLine();
                strbuilder.Append("<br />&nbsp;&nbsp;Password: <b>").Append(strPassword).Append("</b>").AppendLine().AppendLine();
                strbuilder.Append(" <br /><br />Please visit http://www.nena.ca/login.aspx to access your web account.").AppendLine();
                strbuilder.Append("<br />Thank you for your interest in our organization.").AppendLine().AppendLine();
                strbuilder.Append("<br /><br />Sincerely,").AppendLine()
                    .Append("<br />NENA.ca Web Administrators");

                MailMessage omessage = new MailMessage();
                omessage.From = new MailAddress("WebSiteAdministrator@nena.ca", "NENA WebSite Administrator");
                omessage.To.Add(new MailAddress(pMember.EmailAddress));
                omessage.Subject = "NENA.ca Account Created";
                omessage.IsBodyHtml = true;
                omessage.Body = strbuilder.ToString();

                SmtpClient client = new SmtpClient();
                //SmtpClient client = new SmtpClient("rarsk.com", 25);
                //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");

                client.Send(omessage);
        }

                public static void ActivatedAccount(Member pMember)
                {
                    StringBuilder strbuilder = new StringBuilder();

                    strbuilder.Append("Hello ").Append(pMember.FirstName).AppendLine();
                    strbuilder.Append(",<br /><br />This Email is to confirm your NENA.ca web account is active.");
                    strbuilder.Append("<br />Please visit http://www.nena.ca/login.aspx to access your web account.");
                    strbuilder.Append("<br /><br />If you cannot remember your username or password, use the password reset form <br />").Append("http://nena.ca/user/EmailForgottenPassword.aspx");
                    strbuilder.Append("<br /><br />Thank you for being a part of NENA.");
                    strbuilder.Append("<br /><br />Sincerely,").AppendLine().Append("<br />NENA Site Administrators");

                    MailMessage omessage = new MailMessage();
                    omessage.From = new MailAddress("WebSiteAdministrator@nena.ca", "NENA WebSite Administrator");
                    omessage.To.Add(new MailAddress(pMember.EmailAddress));
                    omessage.Subject = "Your NENA.ca Account is enabled";
                    omessage.IsBodyHtml = true;
                    omessage.Body = strbuilder.ToString();

                    SmtpClient client = new SmtpClient();
                    //SmtpClient client = new SmtpClient("rarsk.com", 25);
                    //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");

                    client.Send(omessage);
                }

                public static void RecreatedAccount(Member pMember, string strPassword)
                {
                    StringBuilder strbuilder = new StringBuilder();

                    strbuilder.Append("Hello ").Append(pMember.FirstName).Append(" ")
                        .Append(pMember.LastName).AppendLine();
                    strbuilder.Append("<br /><br />We recently experienced some technical problems on our website which required us to recreate our membership accounts.").AppendLine();
                    strbuilder.Append("<br /><br />below are your new login credentials for our web site: <br />").AppendLine().AppendLine();
                    strbuilder.Append("<br />&nbsp;&nbsp;Username: <b>").Append(pMember.CS_UserName).Append("</b>").AppendLine();
                    strbuilder.Append("<br />&nbsp;&nbsp;Password: <b>").Append(strPassword).Append("</b>").AppendLine().AppendLine();
                    strbuilder.Append(" <br /><br />Please visit http://www.nena.ca/login.aspx to access your web account.").AppendLine();
                    strbuilder.Append("<br />Thank you for being a part of NENA.").AppendLine().AppendLine();
                    strbuilder.Append("<br /><br />Sincerely,").AppendLine()
                        .Append("<br />NENA.ca Web Administrators");

                    MailMessage omessage = new MailMessage();
                    omessage.From = new MailAddress("WebSiteAdministrator@nena.ca", "NENA WebSite Administrator");
                    omessage.To.Add(new MailAddress(pMember.EmailAddress));
                    omessage.Subject = "NENA.ca Account Created";
                    omessage.IsBodyHtml = true;
                    omessage.Body = strbuilder.ToString();

                    SmtpClient client = new SmtpClient();
                    //SmtpClient client = new SmtpClient("rarsk.com", 25);
                    //client.Credentials = new System.Net.NetworkCredential("gpronych", "garyrhd");
                    client.Send(omessage);
                }
    }
}

//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtsperver") = "mailout.accesscomm.ca"
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "gary.pronych"
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "garyrhd"

//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtsperver") = "localhost"
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "pronychgary"
//objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "garyrqhr"

